Skip to content

fix: fetch quota on manual refresh button click#449

Open
woai66 wants to merge 2 commits into
icebear0828:devfrom
woai66:fix/quota-refresh-on-manual-click
Open

fix: fetch quota on manual refresh button click#449
woai66 wants to merge 2 commits into
icebear0828:devfrom
woai66:fix/quota-refresh-on-manual-click

Conversation

@woai66
Copy link
Copy Markdown

@woai66 woai66 commented May 6, 2026

Summary

  • Fetch and cache quota data after manually refreshing a single account
  • Honor quota=fresh on GET /auth/accounts by actively refreshing quotas for active accounts
  • Add tls.disable_websocket config support and fix empty proxy_url handling for environments where WebSocket/proxy behavior needs to be controlled

Problem

After importing or adding accounts, the dashboard could show no quota usage until an account was actually used for a proxy request. Clicking the account refresh button only refreshed the OAuth token and checked health; it did not call the upstream Codex usage API. The top-level refresh button already requested ?quota=fresh, but the backend ignored that parameter.

Solution

  • POST /auth/accounts/:id/refresh now fetches upstream usage via CodexApi.getUsage() after a successful token refresh and stores it via pool.updateCachedQuota().
  • GET /auth/accounts?quota=fresh now refreshes quota for all active accounts before returning the account list.
  • Quota fetch failures are logged per account but do not block health/list refresh responses.

Test Plan

  • Built the web UI with npm run build:web
  • Ran the server locally and imported 3 accounts
  • Verified the single-account refresh button displays 5-hour / 7-day quota without needing proxy traffic first
  • Verified the top-level refresh button refreshes quota data for all active accounts
  • Built a Windows Electron package successfully with cd packages/electron && npm run build && npm run pack:win

woai66 and others added 2 commits May 7, 2026 00:04
Previously, clicking the refresh button on an account card only
refreshed the OAuth token without querying upstream quota data.

Now, after a successful token refresh, we also call the Codex
usage API to fetch and cache the current quota (7-day and 5-hour
windows), so users can see usage data even without making proxy
requests.

Changes:
- POST /auth/accounts/:id/refresh now fetches quota after token refresh
- GET /auth/accounts?quota=fresh actively fetches quota for all accounts
- Added tls.disable_websocket config option for proxies that don't support WebSocket
- Proxy auto-detection now respects empty proxy_url config

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Use getConfig() when checking disable_websocket during implicit resume so the branch builds cleanly.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@icebear0828
Copy link
Copy Markdown
Owner

Review notes:

这个 PR 目前我建议先不要合并,主要风险是它把一个现有代码刻意避开的路径重新加回来了。

现有 src/routes/accounts.ts 和 src/auth/health-check.ts 里已经有明确设计:RT exchange / health-check 只打 OAuth refresh endpoint,不要在刷新 RT 后马上请求 Codex /codex/usage,因为之前标注过这会触发 OpenAI risk detection / deactivation。

但这个 PR 在 POST /auth/accounts/:id/refresh 成功 probeAccount() 后马上 new CodexApi(...).getUsage(),等于手动 refresh 后立刻打 /codex/usage,风险比较高。

另外还有两个实现问题:

  1. GET /auth/accounts?quota=fresh 对所有 active accounts 直接 Promise.allSettled(...getUsage()),没有并发限制;账号多时会瞬间 fan-out 到上游。
  2. 账号列表接口会变成等待所有 upstream quota 请求完成的慢接口,fetchUsage 默认 15s timeout,dashboard 手动刷新体验可能会卡。

建议把 quota fresh 做成单独、受限、可选的路径,复用现有 quota refresher 的 concurrency / throttle 策略;不要挂在 token refresh 的同步路径后面。tls.disable_websocket 这部分也建议拆开或补完整设置入口和测试,尤其 implicit resume 依赖 WebSocket 支持 previous_response_id,禁用后的行为需要明确。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants